package com.honeyms.framework.config;

import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import com.honeyms.common.utils.security.ShiroUtils;

@Configuration
public class WebSocketChatConfig extends ServerEndpointConfig.Configurator{

	/**
	 * 注入honeychat
	 * @return
	 */
	@Bean
	public ServerEndpointExporter serverEndpointExporter() {
		return new ServerEndpointExporter();
	}
	
	@Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        // 将用户信息存储到socket的配置里
        sec.getUserProperties().put("user", ShiroUtils.getSysUser());
        super.modifyHandshake(sec, request, response);
    }
}
